package com.baichang.taoshunda.dao.impl;

import com.baichang.taoshunda.dao.GoodsReportDao;
import com.baichang.taoshunda.entity.GoodsReport;
import com.baichang.framework.dao.impl.BaseDaoImpl;
import com.baichang.framework.model.Page;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/11/14 0014.
 */
@Repository
public class GoodsReportDaoImpl extends BaseDaoImpl<GoodsReport> implements GoodsReportDao {

    /**
     * 查询举报的商品
     *
     * @param nowPage
     * @param pageSize
     * @param name
     * @param busName  @return
     */
    @Override
    public Page queryReportGoods(int nowPage, int pageSize, String name, String busName) {
        List list = new ArrayList();
        String sql = "SELECT tg.*,tc.nick_name AS nickName FROM t_goods_report gr INNER JOIN t_goods tg ON tg.id=gr.goods_id " +
                "INNER JOIN t_company tc ON tc.id=tg.company_id WHERE tg.status=1 AND tc.status=1 AND tg.is_upper=1";
        if (StringUtils.isNotBlank(name)) {
            sql += " AND tg.name LIKE ?";
            list.add("%" + name + "%");
        }
        if (StringUtils.isNotBlank(busName)) {
            sql += " AND tc.nick_name LIKE ?";
            list.add("%" + busName + "%");
        }
        return pageForMapList(sql, nowPage, pageSize, list.toArray());
    }
}
